package com.github.jeffreyning.mybatisplus.demo;


//import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
//import com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties;
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties;
import com.baomidou.mybatisplus.core.MybatisConfiguration;
import com.baomidou.mybatisplus.core.config.GlobalConfig;
//import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
//import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
//import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
import com.github.jeffreyning.mybatisplus.base.MppSqlInjector;
import com.github.jeffreyning.mybatisplus.conf.EnableAutoFill;
import com.github.jeffreyning.mybatisplus.conf.EnableKeyGen;
import com.github.jeffreyning.mybatisplus.conf.EnableMPP;
import com.github.jeffreyning.mybatisplus.handler.DataAutoFill;
import com.github.jeffreyning.mybatisplus.handler.MppKeyGenerator;
//import com.github.jeffreyning.mybatisplus.plugin.MppPaginationInterceptor;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

/**
 * @author ninghao
 * @className PlusDemoApplication
 * @description mybatisplus-plus使用demo
 * @date 2020/11/24
 */
@SpringBootApplication
@EnableMPP//启动mpp配置初始化
@EnableAutoFill//启动字段自动注入
@EnableKeyGen//启动主键自动生成
//@MapperScan(basePackages= {"com.github.jeffreyning.mybatisplus.demo.mapper"})
public class PlusDemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(PlusDemoApplication.class, args);
    }


    //自定义SqlSessionFactory时需手工注入mppSqlInjector、dataAutoFill、mppKeyGenerator
/*    @Bean
    public SqlSessionFactory sqlSessionFactory(DataSource dateSource, MybatisPlusProperties properties, MppSqlInjector mppSqlInjector, MppKeyGenerator mppKeyGenerator, DataAutoFill dataAutoFill) throws Exception {
        MybatisSqlSessionFactoryBean bean=new MybatisSqlSessionFactoryBean();
        GlobalConfig globalConfig = properties.getGlobalConfig();
        globalConfig.setSqlInjector(mppSqlInjector);
        globalConfig.setMetaObjectHandler(dataAutoFill);
        globalConfig.getDbConfig().setKeyGenerator(mppKeyGenerator);
        bean.setDataSource(dateSource);
        bean.setGlobalConfig(globalConfig);
        return bean.getObject();
    }*/
/*
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new MppPaginationInterceptor();
    }
*/
/*    @Bean
    ConfigurationCustomizer mybatisConfigurationCustomizer() {
        return new ConfigurationCustomizer() {
            @Override
            public void customize(Configuration configuration) {
                configuration.addInterceptor(new com.github.pagehelper.PageInterceptor());
            }
        };
    }*/


}
